package com.smart.modules.genealogy.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.modules.genealogy.domain.PersonRelationship;
import com.smart.modules.genealogy.service.IPersonRelationshipService;
import com.smart.system.common.result.Result;
import com.smart.system.common.result.PageResult;


/**
 * 人员关系Controller
 */
@RestController
@RequestMapping("/genealogy/relationship")
public class PersonRelationshipController
{
    @Autowired
    private IPersonRelationshipService personRelationshipService;

    /**
     * 查询人员关系列表
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:relationship:list')")
    @GetMapping("/list")
    public PageResult list(PersonRelationship personRelationship)
    {

        IPage<PersonRelationship> pageModel = new Page<PersonRelationship>(personRelationship.getPageNum(),personRelationship.getPageSize());
        IPage<PersonRelationship> page = personRelationshipService.selectPersonRelationshipList(pageModel,personRelationship);
        return PageResult.success(page);
    }


    /**
     * 获取人员关系详细信息
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:relationship:query')")
    @GetMapping(value = "/{personId}")
    public Result getInfo(@PathVariable("personId") Long personId)
    {
        return Result.success(personRelationshipService.selectPersonRelationshipByPersonId(personId));
    }

    /**
     * 新增人员关系
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:relationship:add')")
    @PostMapping
    public Result add(@RequestBody PersonRelationship personRelationship)
    {
        return Result.success(personRelationshipService.insertPersonRelationship(personRelationship));
    }

    /**
     * 修改人员关系
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:relationship:edit')")
    @PutMapping
    public Result edit(@RequestBody PersonRelationship personRelationship)
    {
        return Result.success(personRelationshipService.updatePersonRelationship(personRelationship));
    }

    /**
     * 删除人员关系
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:relationship:remove')")
    @DeleteMapping("/{personIds}")
    public Result remove(@PathVariable Long[] personIds)
    {
        return Result.success(personRelationshipService.deletePersonRelationshipByPersonIds(personIds));
    }
}
